package gui.lesson03;

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class TestKey {
    public static void main(String[] args) {
        new FrameKey();
    }
}
//监听键盘的类
class FrameKey extends Frame{
    public FrameKey(){
        setBounds(200,200,300,200);
        setVisible(true);
        //键盘按下
        this.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                //获取键盘下的键是哪一个，当前的码
                int keyCode = e.getKeyCode();
                System.out.println("我按下的键盘所对应的码"+keyCode);
                if (keyCode==KeyEvent.VK_W){
                    System.out.println("我按下了W键");
                }
            }
        });
    }
}